package com.xgg.taiwuinfo.filter;

import android.content.Context;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;

import com.xgg.taiwuinfo.R;

import org.json.JSONObject;

import java.util.List;
import java.util.Map;

public abstract class FC_ContainEdit extends FilterComponent {

    protected String ReadValue;
    public String TempValue;

    public FC_ContainEdit()
    {
        text_listener = new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                TempValue = charSequence.toString();
            }

            @Override
            public void afterTextChanged(Editable editable) {}
        };
    }

    @Override
    final public int getItemLayout(){ return R.layout.item_fc_containedit; }

    @Override
    final public void save()
    {
        ReadValue = TempValue;
    }

    @Override
    final public JSONObject getJsonObj()
    {
        JSONObject obj = new JSONObject();
        try
        {
            obj.put("id" , mTypeId);
            obj.put("v" , ReadValue);
        }
        catch (Exception e)
        {
            Log.d("SaveJson" , e.getLocalizedMessage());
        }
        return obj;
    }

    @Override
    final public void discard(){
        TempValue = ReadValue;
    }

    @Override
    final public boolean isEdited()
    {
        return (!ReadValue.equals(TempValue)) ;
    }

    @Override
    final public List<Map<String, String>> getCompareString(Context ctx){
        return null;
    }

    @Override
    final public String getDesc()
    {
        return String.format("%s %s [%s]\r\n" , FieldStr , CompStr , ReadValue);
    }
}
